function btnNew_onclick()
{
    var txtID=document.getElementById("txtID");
    txtID.value = "";
    var txtFName=document.getElementById("txtFName");
    txtFName.value = "";
    var txtLName=document.getElementById("txtLName");
    txtLName.value = "";
    var txtCityOfBirth=document.getElementById("txtCityOfBirth");
    txtCityOfBirth.value = "";
    var txtFounderOf=document.getElementById("txtFounderOf");
    txtFounderOf.value = "";
}

function btnFirst_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Position","First"));
    window.alert(argsArray.join("&"));
    sendRequest("GetPerson.jsp",argsArray,show);
}

function btnSave_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Add"));
    var txtID=document.getElementById("txtID");
    argsArray.push(newArg("ID",txtID.value));
    var txtFName=document.getElementById("txtFName");
    argsArray.push(newArg("FName",txtFName.value));
    var txtLName=document.getElementById("txtLName");
    argsArray.push(newArg("LName",txtLName.value));
    var txtCityOfBirth=document.getElementById("txtCityOfBirth");
    argsArray.push(newArg("CityOfBirth",txtCityOfBirth.value));
    var txtFounderOf=document.getElementById("txtFounderOf");
    argsArray.push(newArg("FounderOf",txtFounderOf.value));
    window.alert(argsArray.join("&"));
    sendRequest("ChangePerson.jsp",argsArray,btnSave_onclick_response);
}

function btnSave_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0)
        window.alert("OK");
      else
          window.alert("Error");
    }
  }

}

function btnDelete_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Delete"));
    var txtID=document.getElementById("txtID");
    argsArray.push(newArg("ID",txtID.value));
    window.alert(argsArray.join("&"));
    sendRequest("ChangePerson.jsp",argsArray,btnDelete_onclick_response);
}

function btnDelete_onclick_response()
{
    if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0)
        window.alert("OK");
      else
          window.alert("Error");
    }
  }
}

function btnUpdate_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Action","Update"));
    var txtID=document.getElementById("txtID");
    argsArray.push(newArg("ID",txtID.value));
    var txtFName=document.getElementById("txtFName");
    argsArray.push(newArg("FName",txtFName.value));
    var txtLName=document.getElementById("txtLName");
    argsArray.push(newArg("LName",txtLName.value));
    var txtCityOfBirth=document.getElementById("txtCityOfBirth");
    argsArray.push(newArg("CityOfBirth",txtCityOfBirth.value));
    var txtFounderOf=document.getElementById("txtFounderOf");
    argsArray.push(newArg("FounderOf",txtFounderOf.value));
    window.alert(argsArray.join("&"));
    sendRequest("ChangePerson.jsp",argsArray,btnUpdate_onclick_response);
}

function btnUpdate_onclick_response()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval("("+res+")");
      if(info.errorcode == 0)
        window.alert("OK");
      else
          window.alert("Error");
    }
  }

}

function btnPrevious_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Position","Previous"));
    var txtID=document.getElementById("txtID");
    argsArray.push(newArg("ID",txtID.value));
    window.alert(argsArray.join("&"));
    sendRequest("GetPerson.jsp",argsArray,show);
}

function btnNext_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Position","Next"));
    var txtID=document.getElementById("txtID");
    argsArray.push(newArg("ID",txtID.value));
    window.alert(argsArray.join("&"));
    sendRequest("GetPerson.jsp",argsArray,show);
}

function btnLast_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Position","Last"));
    window.alert(argsArray.join("&"));
    sendRequest("GetPerson.jsp",argsArray,show);
}

function btnFind_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("Position","Find"));
    var txtFindID=document.getElementById("txtFindID");
    argsArray.push(newArg("ID",txtFindID.value));
    window.alert(argsArray.join("&"));
    sendRequest("GetPerson.jsp",argsArray,show);
}


function show()
{
  if (isValidResponse(this))
  {
    var res=this.responseText;
    if(res!="")
    {
      var info=eval('(' + res + ')');
      if(info.data.length > 0)
      {
        var txtID=document.getElementById("txtID");
        txtID.value=info.data[0].per_id;
        var txtFName=document.getElementById("txtFName");
        txtFName.value=info.data[0].per_fname;
        var txtLName=document.getElementById("txtLName");
        txtLName.value=info.data[0].per_lname;
        var txtCityOfBirth=document.getElementById("txtCityOfBirth");
        txtCityOfBirth.value=info.data[0].per_cityofbirth;
        var txtFounderOf=document.getElementById("txtFounderOf");
        txtFounderOf.value=info.data[0].per_founderof;
      }
      else
        window.alert("Not Found!!");
    }
  }
}